package com.fangzhi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fangzhi.mapper.AdminAccountInfoMapper;
import com.fangzhi.mobel.Commission;
import com.fangzhi.mobel.vo.TopVo;
import com.fangzhi.service.CommissionService;
import com.fangzhi.mapper.CommissionMapper;
import com.fangzhi.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
* @author edy
* @description 针对表【commission】的数据库操作Service实现
* @createDate 2024-10-08 17:30:57
*/
@Service
public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commission>
    implements CommissionService{

    @Autowired
    private AdminAccountInfoMapper adminAccountInfoMapper;

    @Override
    public ResponseResult top(YearMonth time) {

        LocalDate localDate = time.atDay(1);
        String format = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        List<TopVo.Top> salesTop = this.getBaseMapper().salesTop(time);
        List<TopVo.Top> commissionTop = this.getBaseMapper().commissionTop(format);
        List<TopVo.Top> wxTop = adminAccountInfoMapper.wxTop();
        List<TopVo.Top> deptSaleTop = this.getBaseMapper().deptSalesTop(time);
        TopVo topVo = new TopVo().setWxTop(wxTop).setCommissionTop(commissionTop).setSalesTop(salesTop).setDeptSaleTop(deptSaleTop);
        if (!salesTop.isEmpty())
            topVo.setUserTop(salesTop.get(0));
        return ResponseResult.OK(topVo);
    }
}




